package com.example.springbean.component;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @Author: suichen
 * @Date: 2022-05-08 21:48
 * @Description: SpringBean的后置处理器
 */
@Component
public class MySpringBeanProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof MySpringBean) {
            System.err.println("Bean实现了BeanPostProcessor接口,调用postProcessBeforeInitialization()");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof MySpringBean) {
            System.err.println("Bean实现了BeanPostProcessor接口,postProcessAfterInitialization()");
        }
        return bean;
    }

}
